package cn.liu.knowledge.controller;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.*;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.core.io.InputStreamResource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("embedding")
@AllArgsConstructor
public class EmbeddingController {

    private final EmbeddingModel embeddingModel;

    @SneakyThrows
    @PostMapping()
    public EmbeddingResponse embedding() {
        Document doc = Document.builder().text("当用户传入提问之后，大模型会从已有的Agent（被@Agent标注的类）中选择一个执行，如果没有匹配到大模型会自己回答。\n").build();
        List<Document> documents = List.of(doc);


        List<float[]> embeddings = this.embeddingModel.embed(documents, EmbeddingOptionsBuilder.builder().build(), new TokenCountBatchingStrategy());

//        EmbeddingRequest request = new EmbeddingRequest(List.of("Hello World", "World is big and salvation is near"),
//                OllamaOptions.builder().model("zyw0605688/gte-large-zh:latest").build());
        EmbeddingResponse helloWorld = embeddingModel.embedForResponse(List.of("Hello World", "World is big and salvation is near"));
        return helloWorld;
    }
}
